package com.demo.gereric;

import java.lang.reflect.Field;

public class EraseHolder<T> {
	T data;

	public EraseHolder(T data) {
		this.data = data;
	}

	public static void main(String[] args) {
		EraseHolder<String> holder = new EraseHolder<>("hello");
		Class clazz = holder.getClass();
		System.out.println("erasure class is:" + clazz.getName());

		Field[] fs = clazz.getDeclaredFields();
		for (Field f : fs) {
			System.out.println("Field name " + f.getName() + " type:" + f.getType().getName());
		}

		EraseHolder2<String> holder2 = new EraseHolder2<>("hello");
		clazz = holder2.getClass();
		fs = clazz.getDeclaredFields();
		for (Field f : fs) {
			System.out.println("Field name " + f.getName() + " type:" + f.getType().getName());
		}
	}

	/**
	 * 指定通配符上线
	 * @param <T>
	 */
	static class EraseHolder2<T extends String> {
		T data;

		public EraseHolder2(T data) {
			this.data = data;
		}
	}
}
